﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Frw.Windows.Services.Monitor
{
    public partial class MonitorBase : Form
    {
        public event EventHandler Started;
        public event EventHandler Stopped;
        public event EventHandler Paused;
        public event EventHandler Resumed;
        public event EventHandler Restarted;

        public bool m_contextMenuVisible = false;

        public MonitorBase()
        {
            InitializeComponent();

            this.Icon = this.notifyIcon1.Icon;
        }

        private void MonitorBase_Resize(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                ShowInTaskbar = false;
                notifyIcon1.Visible = true;
                notifyIcon1.ShowBalloonTip(1000);
            }
        }

        private void MonitorBase_Load(object sender, EventArgs e)
        {
            notifyIcon1.BalloonTipText = "Service Monitor";
            notifyIcon1.BalloonTipTitle = "Service Monitor";
        }

        private void MonitorBase_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason != CloseReason.FormOwnerClosing)
            {
                    e.Cancel = true;
                    WindowState = FormWindowState.Minimized;
 
                    //if (notifyIcon1 != null)
                    //{
                    //    notifyIcon1.Icon = null;
                    //    notifyIcon1.Visible = false;
                    //    notifyIcon1.Dispose();
                    //}
                
            }
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ShowInTaskbar = true;
            notifyIcon1.Visible = false;
            WindowState = FormWindowState.Normal;
        }

        private void actionsToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void startToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OnStart(sender, e);
        }

        private void stopToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OnStop(sender, e);
        }

        private void pauseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OnPause(sender, e);
        }

        private void resumeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OnResume(sender, e);
        }

        private void restartToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OnRestart(sender, e);
        }

        private void tsbStart_Click(object sender, EventArgs e)
        {
            OnStart(sender, e);
        }

        private void tsbStop_Click(object sender, EventArgs e)
        {
            OnStop(sender, e);
        }

        private void tsbPause_Click(object sender, EventArgs e)
        {
            OnPause(sender, e);
        }

        private void tsbResume_Click(object sender, EventArgs e)
        {
            OnResume(sender, e);
        }

        private void tsbRestart_Click(object sender, EventArgs e)
        {
            OnRestart(sender, e);
        }

        private void OnStart(object sender, EventArgs e)
        {
            if (Started != null)
            {
                Started(sender, e);
            }
        }

        private void OnStop(object sender, EventArgs e)
        {
            if (Stopped != null)
            {
                Stopped(sender, e);
            }
        }

        private void OnPause(object sender, EventArgs e)
        {
            if (Paused != null)
            {
                Paused(sender, e);
            }
        }

        private void OnResume(object sender, EventArgs e)
        {
            if (Resumed != null)
            {
                Resumed(sender, e);
            }
        }

        private void OnRestart(object sender, EventArgs e)
        {
            if (Restarted != null)
            {
                Restarted(sender, e);
            }
        }

        private void startToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OnStart(sender, e);
        }

        private void stopToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OnStop(sender, e);
        }

        private void pauseToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OnPause(sender, e);
        }

        private void resumeToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OnResume(sender, e);
        }

        private void restartToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OnRestart(sender, e);
        }
    }
}
